<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>

<head>
<style type="text/css">
body {white-space: pre-wrap;
font-family:"Monospaced.plain",Monospace;
font-size:12px;
}
</style>
</head>
<body><span style = "background-color: #F0F0F0;">  0</span>| <span style="color: rgb(255,0,0)">#include &#60;iostream&#62;</span>
<span style = "background-color: #F0F0F0;">  1</span>| <span style="color: rgb(255,0,0)">#include &#60;vector&#62;</span>
<span style = "background-color: #F0F0F0;">  2</span>| <span style="color: rgb(255,0,0)">#include &#60;string&#62;</span>
<span style = "background-color: #F0F0F0;">  3</span>| <span style="color: rgb(255,0,0)">#include &#60;algorithm&#62;//sort();</span>
<span style = "background-color: #F0F0F0;">  4</span>| <span style="color: rgb(0,0,255)">using</span> <span style="color: rgb(0,0,255)">namespace</span> std;
<span style = "background-color: #F0F0F0;">  5</span>| 
<span style = "background-color: #F0F0F0;">  6</span>| <span style="color: rgb(0,0,255)">struct</span> student
<span style = "background-color: #F0F0F0;">  7</span>| {
<span style = "background-color: #F0F0F0;">  8</span>|     string  name;
<span style = "background-color: #F0F0F0;">  9</span>|     string stuNo;
<span style = "background-color: #F0F0F0;"> 10</span>|     <span style="color: rgb(0,0,255)">int</span> math;
<span style = "background-color: #F0F0F0;"> 11</span>|     <span style="color: rgb(0,0,255)">int</span> english;
<span style = "background-color: #F0F0F0;"> 12</span>| };
<span style = "background-color: #F0F0F0;"> 13</span>| student data [10010];
<span style = "background-color: #F0F0F0;"> 14</span>| <span style="color: rgb(0,0,255)">int</span> size ;
<span style = "background-color: #F0F0F0;"> 15</span>| <span style="color: rgb(0,0,255)">bool</span> cmp1(student a,student b)<span style="color: rgb(128,128,128)">//比较函数 学号作关键字 升序</span>
<span style = "background-color: #F0F0F0;"> 16</span>| {
<span style = "background-color: #F0F0F0;"> 17</span>|     <span style="color: rgb(0,0,255)">return</span> a.stuNo&#60;b.stuNo;
<span style = "background-color: #F0F0F0;"> 18</span>| }
<span style = "background-color: #F0F0F0;"> 19</span>| <span style="color: rgb(0,0,255)">bool</span> cmp2(student a,student b)<span style="color: rgb(128,128,128)">//比较函数 数学作关键字 降序</span>
<span style = "background-color: #F0F0F0;"> 20</span>| {
<span style = "background-color: #F0F0F0;"> 21</span>|     <span style="color: rgb(0,0,255)">return</span> a.math&#62;b.math;
<span style = "background-color: #F0F0F0;"> 22</span>| }
<span style = "background-color: #F0F0F0;"> 23</span>| <span style="color: rgb(0,0,255)">int</span> main()
<span style = "background-color: #F0F0F0;"> 24</span>| {
<span style = "background-color: #F0F0F0;"> 25</span>|     <span style="color: rgb(128,128,128)">//sort 函数 第一个参数系起始地址 第二个是结束地址（往后取） 第三个比较函数（可不写（非自定义数据） 默认升序）</span>
<span style = "background-color: #F0F0F0;"> 26</span>|     sort(data,data+size,cmp1);<span style="color: rgb(128,128,128)">//学号作关键字 升序</span>
<span style = "background-color: #F0F0F0;"> 27</span>|     sort(data,data+size,cmp2);<span style="color: rgb(128,128,128)">//可写成sort(&#38;data[0],&#38;data[size],cmp2);</span>
<span style = "background-color: #F0F0F0;"> 28</span>|     <span style="color: rgb(0,0,255)">return</span> 0;
<span style = "background-color: #F0F0F0;"> 29</span>| }
</body>
</html>
